# 包含目录
include_directories(
    ${CMAKE_SOURCE_DIR}/include
)

# 设置源文件
set(MQTT_SENDER_SOURCES
    main.c
    file_sender.c
)

set(MQTT_RECEIVER_SOURCES
    main.c
    file_receiver.c
)

# 添加发送端可执行文件
add_executable(mqtt_sender ${MQTT_SENDER_SOURCES})

# 添加接收端可执行文件
add_executable(mqtt_receiver ${MQTT_RECEIVER_SOURCES})

# 链接库 - 直接链接库文件，不使用find_package
target_link_libraries(mqtt_sender
    nanosdk
    jansson
    ssl
    crypto
    ${CMAKE_THREAD_LIBS_INIT}
    m
    pthread
    dl
)

target_link_libraries(mqtt_receiver
    nanosdk
    jansson
    ssl
    crypto
    ${CMAKE_THREAD_LIBS_INIT}
    m
    pthread
    dl
)

# 设置目标属性
set_target_properties(mqtt_sender PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

set_target_properties(mqtt_receiver PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 复制配置文件（如果需要）
if(EXISTS ${CMAKE_SOURCE_DIR}/config)
    file(GLOB CONFIG_FILES ${CMAKE_SOURCE_DIR}/config/*)
    file(COPY ${CONFIG_FILES} DESTINATION ${CMAKE_BINARY_DIR}/config)
endif()
